import gtk

class ResizeDialog(gtk.Dialog):
    def __init__(self):
        # Construct superclass.
        gtk.Dialog.__init__(self, 'Select Resolution')
        
        # Add buttons.
        self.add_button(gtk.STOCK_CANCEL, 0)
        self.add_button(gtk.STOCK_OK, 1)

        # Add other widgets.
        self.rb_640x480 = gtk.RadioButton(None, '640x480')
        self.vbox.pack_start(self.rb_640x480)
        self.rb_800x600 = gtk.RadioButton(self.rb_640x480, '800x600')
        self.vbox.pack_start(self.rb_800x600)
        self.rb_1024x768 = gtk.RadioButton(self.rb_640x480, '1024x768')
        self.vbox.pack_start(self.rb_1024x768)
        self.rb_1280x1024 = gtk.RadioButton(self.rb_640x480, '1280x1024')
        self.vbox.pack_start(self.rb_1280x1024)
        self.rb_1600x1200 = gtk.RadioButton(self.rb_640x480, '1600x1200')
        self.vbox.pack_start(self.rb_1600x1200)
        self.vbox.pack_start(gtk.HSeparator())
        self.maintain_aspect = gtk.CheckButton("Maintain aspect")
        self.maintain_aspect.set_active(True)
        self.vbox.pack_start(self.maintain_aspect)

    def do_it(self):
        self.show_all()
        rc = self.run()
        self.hide_all()
        if rc == 1:
            # Ok button was clicked. Return the chosen resolution.
            if self.rb_640x480.get_active():
                return ((640, 480), self.maintain_aspect.get_active())
            elif self.rb_800x600.get_active():
                return ((800, 600), self.maintain_aspect.get_active())
            elif self.rb_1024x768.get_active():
                return ((1024, 768), self.maintain_aspect.get_active())
            elif self.rb_1280x1024.get_active():
                return ((1280, 1024), self.maintain_aspect.get_active())
            elif self.rb_1600x1200.get_active():
                return ((1600, 1200), self.maintain_aspect.get_active())
        else:
            # Cancel was clicked. Return an error indicator.
            return None
